#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<unordered_map>
using namespace std;



// Definition for Employee.
class Employee {
public:
    Employee(int id,int importance, vector<int> subordinates);
public:
    int id;
    int importance;
    vector<int> subordinates;
};


class Solution {
public:
    int getImportance(vector<Employee*> employees, int id) {
        unordered_map<int,pair<int,vector<int>>> UM;
        for(int i = 0;i<employees.size();++i){
            UM[employees[i]->id] = make_pair(employees[i]->importance,employees[i]->subordinates);
        }
        int sum = 0;
        func(UM,id,sum);
        return sum;
        
    }
    void func(unordered_map<int,pair<int,vector<int>>>& UM,int id,int& sum){
        if(UM[id].second.empty()){
            sum+=UM[id].first;
            return;
        }
        if(UM.find(id)!=UM.end()){
            sum += UM[id].first;
            for(int i = 0;i<UM[id].second.size();++i){
                func(UM,(UM[id].second)[i],sum);
            }
        }
        return ;
    }
};